import Request from "@/sdk/pocky-request/index.js";

export default {
	/**
	 * @description 用户注册
	 * @param {Object} postData
	 * postData:{
	 *	username	//用户名
	 *  password	//密码
	 *  code   //短信验证码
	 * }
	 */
	userRegister(postData) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/common/regist.do',
				method: 'post',
				data: postData
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过用户名和密码登录
	 * @param {String} uName 用户名
	 * @param {String} uPass 用户密码
	 */
	loginByName(uName, uPass) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/common/login.do',
				method: 'post',
				data: {
					username: uName,
					password: uPass
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description  通过短信验证码登录
	 * @param {Object} tel 手机号
	 * @param {Object} msgCode 验证码
	 */
	loginByMsgCode(tel, msgCode) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/common/login.do',
				method: 'post',
				data: {
					username: tel,
					code: msgCode,
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 用户退出
	 * @param {Object} userId
	 */
	logOut(token) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/common/logout.do',
				method: 'post',
				data: {
					token: token
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 通过短信验证码设置新密码
	 * @param {String} uName	
	 * @param {String} newPass
	 * @param {String} msgCode
	 */
	findPass(uName, newPass, msgCode) {
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/user/modify_password.do',
				method: 'post',
				data: {
					username: uName,
					password: newPass,
					code: msgCode
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 修改用户头像
	 * @param {Object} picPath
	 * 
	 */
	editUserPic(userId, picPath) {
		let _this = this;
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/user/update_info.do',
				method: 'post',
				data: {
					userId: userId,
					pic: picPath
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 换绑手机号时验证旧手机号
	 * @param {Object} tel
	 * @param {Object} code
	 */
	checkOldTel(tel, code) {
		let _this = this;
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/user/verify_phone.do',
				method: 'post',
				data: {
					phone: tel,
					code: code
				}
			})
			resolve(instance)
		})
	},
	/**
	 * @description 绑定新手机号
	 * @param {Object} userId
	 * @param {Object} newTel
	 * @param {Object} code
	 */
	bindNewTel(userId, newTel, code) {
		let _this = this;
		return new Promise(resolve => {
			let r = Request();
			let instance = r.request({
				url: '/user/update_phone.do',
				method: 'post',
				data: {
					userId: userId,
					phone: newTel,
					code: code
				}
			})
			resolve(instance)
		})
	},
}